//
//  Single+CBResponse.swift
//  Moya_Rx
//
//  Created by fst on 2019/12/26.
//  Copyright © 2019 fst. All rights reserved.
//

import Foundation
import HandyJSON
import RxSwift
import Moya

public extension PrimitiveSequence where Trait == SingleTrait, Element == Response {
    func mapObject<T: HandyJSON>(_ type: T.Type) -> Single<T> {
        return flatMap { response -> Single<T> in
                    return Single.just(try response.mapObject(type))
                }
    }
    
    func mapArray<T: HandyJSON>(_ type: T.Type) -> Single<[T]> {
        return flatMap { response -> Single<[T]> in
                    return Single.just(try response.mapArray(type))
       }
    }
}
